-- SERVER SIDE

-- Creates the Database
ClassesDB = "apple_tdm_classe2"
if sql.TableExists(ClassesDB) then
MsgC(Color(255,255,255),"[",Color(255,0,0),"TDM-ClassesDB",Color(255,255,255),"] Database '"..ClassesDB.."' Already Exists!\n")
	else
		if (!sql.TableExists(ClassesDB)) then
			local Query = "CREATE TABLE "..ClassesDB.." ( ID int, Name varchar(255), Weapons text )"
			local Result = sql.Query(Query)
			if (sql.TableExists(ClassesDB)) then
				--MsgN("[TDM-TeamCreation] Successfully Created Database 'apple_tdm_teamcreation22'!")
				MsgC(Color(255,255,255),"[",Color(255,0,0),"TDM-ClassesDB",Color(255,255,255),"] Successfully Created Database '"..ClassesDB.."'!\n")
			else
				--MsgN("[TDM-TeamCreation] Database 'apple_tdm_teamcreation22' Was Not Created!")
				MsgC(Color(255,255,255),"[",Color(255,0,0),"TDM-ClassesDB",Color(255,255,255),"] Database '"..ClassesDB.."' Was Not Created!\n")
				MsgN( sql.LastError( Result ) )
			end	
		end
end


function TDMCreateClass(len, ply)
if !ply:IsSuperAdmin() then return end

local ClassName = net.ReadString( )

local LastClassIDCreated = tonumber(sql.QueryValue( "SELECT ID FROM "..ClassesDB.." ORDER BY ID DESC LIMIT 1" ))
if LastClassIDCreated == nil then
	LastClassIDCreated = 0
end

local LastClassIDCreated = (LastClassIDCreated + 1)
	--MsgN("[TDM-TeamCreation] Team Was Created Successfully, TeamID: "..LastClassIDCreated)
	MsgC(Color(255,255,255),"[",Color(255,0,0),"TDM-ClassesAdd",Color(255,255,255),"] Class Was Created Successfully, ClassID: ",Color(0,255,0),""..LastClassIDCreated.."\n")
	sql.Query( "INSERT INTO "..ClassesDB.." (`ID`, `Name`, `Weapons`) VALUES ('"..tonumber(LastClassIDCreated).."', '"..TeamName.."' ) ")
AutoFixTeamID()

end
net.Receive("TDMCreateClass", TDMCreateClass)